#include"processbar.h"
#include<string.h>
#include<unistd.h>
//extern void ForTest()
//{
//  printf("this is for test");
//  printf("this is for test");
//  printf("this is for test");
//  printf("this is for test");
//  printf("this is for test");
//  printf("this is for test");
//}

#define len 101
#define sty '='
const char *lable="|/-\\";

//void procbar(){
//  char bar[len];
//  memset(bar,'\0',sizeof(bar));
//  int clen=strlen(lable);
//  int cnt=0;
//  while(cnt<=100){
//    printf("[%-100s][%d%%][%c]\r",bar,cnt,lable[cnt%clen]);
//    fflush(stdout);
//    bar[cnt++]=sty;
//
//    usleep(30000);
//  }
//  printf("\n");
//
//}


void procbar(double total,double current)
{
  char bar[len];
  memset(bar,'\0',sizeof(bar));
  int clen=strlen(lable);
  int cnt=0;
  
  double rate=(current*100.0)/total;
  int loop_count=(int)rate;

  while(cnt<=loop_count){
    printf("[%-100s][%.1lf%%][%c]\r",bar,rate,lable[cnt%clen]);
    fflush(stdout);
    bar[cnt++]=sty;

    //usleep(30000);
  }

}

